{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from torch.utils.data import DataLoader"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 准备数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "sentences = [\n",
    "    '我爱学习编程语言，非常有趣。',\n",
    "    '今天天气不错，适合出去玩。',\n",
    "    '学习新知识让人快乐。',\n",
    "    '努力学习，天天向上。',\n",
    "    '知识改变命运，学习无止境。',\n",
    "    '春风吹又生。',\n",
    "    '花开堪折直须折，莫待无花空折枝。',\n",
    "    '风吹草地见牛羊，日暖花枝见蜜蜂。',\n",
    "    '山不厌高，海不厌深。',\n",
    "    '这是一条数据'\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 ['我爱学习编程语言，非常有趣。', '今天天气不错，适合出去玩。', '学习新知识让人快乐。'] 3\n",
      "2 ['努力学习，天天向上。', '知识改变命运，学习无止境。', '春风吹又生。'] 3\n",
      "3 ['花开堪折直须折，莫待无花空折枝。', '风吹草地见牛羊，日暖花枝见蜜蜂。', '山不厌高，海不厌深。'] 3\n",
      "4 ['这是一条数据'] 1\n"
     ]
    }
   ],
   "source": [
    "batch_size = 3\n",
    "data_loader = DataLoader(sentences, batch_size=batch_size)\n",
    "\n",
    "i = 0\n",
    "for batch in data_loader:\n",
    "  i = i + 1\n",
    "  print(i, batch, len(batch))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
